import requests


class SendMethod:

    @staticmethod
    def send_method(method, url, params=None, data=None, json=None):
        if method == 'get':
            response = requests.get(url=url, params=params)
        elif method == 'post':
            response = requests.post(url=url, data=data)
        else:
            response = None
            print('请求错误！')

        result = {}
        if response is not None:
            result['status_code'] = response.status_code
            result['headers'] = response.headers
            result['body'] = response.json()
            result['response_time'] = int(response.elapsed.microseconds / 1000)
            return result

if __name__ == '__main__':
    url = 'http://127.0.0.1:8000/api/add_event/'
    payload = {
        'eid':1222,
        'name':'requests发布会',
        'limit':3,
        'status':1,
        'address':'A4教室',
        'start_time':'2023-7-31 12:30:30'
    }
    method = 'post'
    print(SendMethod.send_method(method,url,data=payload))



